package vn.edu.saigontech.ncms.model.comparator;

import java.util.Calendar;
import java.util.Comparator;

import vn.edu.saigontech.ncms.model.system.DayOff;
import vn.edu.saigontech.ncms.util.DateUtil;

public class DayOffComparator implements Comparator<DayOff> {

	@Override
	public int compare(DayOff dayOff1, DayOff dayOff2) {
		Boolean yearly1 = dayOff1.isYearlyRepeat();
		Boolean yearly2 = dayOff2.isYearlyRepeat();
		if(yearly1.equals(yearly2)) {
			Calendar cal1 = DateUtil.toCalendar(dayOff1.getDate());
			Calendar cal2 = DateUtil.toCalendar(dayOff2.getDate());
			if(yearly1 == true && yearly2 == true) {
				cal1.set(Calendar.YEAR, cal2.get(Calendar.YEAR));
			}
			return cal1.compareTo(cal2);
		}
		return yearly2.compareTo(yearly1);
	}
}